package com.example.nio.security.custom;

import cn.hutool.json.JSONUtil;
import com.example.nio.commons.User;
import com.example.nio.config.RedisConfig;
import com.example.nio.security.config.MyAuthorityPermit;
import com.example.nio.security.dmo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Collection;

@Component
public class MyAuthorityPermitImpl implements MyAuthorityPermit {
    @Autowired
    private RedisConfig redisConfig;

    // 权限认证的方法
    public boolean hasAuthority(HttpServletRequest request, Authentication authentication){
        String authorization = request.getHeader("authorization");
        String token = redisConfig.getStringBySer(authorization);
        if (token != null && !"".equals(token)){

            System.out.println("认证成功");
            return true;
        }else{
            System.out.println("redis中找不到对应的token验证");
            return false;
        }
    }
}
